package symbols;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

/**
 * 
 * @author Balazs Pete
 *
 */
public class SymbolButton extends JButton {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String value = "";
	private String outValue = "";
	public String label;
	
	/**
	 * Creates a button
	 */
	public SymbolButton(){
		new JButton();
		addListener();
	}
	
	/**
	 * Creates a button with it's corresponding symbol value (value is label)
	 * @param value corresponding value
	 */
	public SymbolButton(String val){
		value = val;
		new JButton();
		setText(value);
		addListener();
	}
	
	/**
	 * Creates a button with it's corresponding symbol value (value is label)
	 * @param value corresponding value
	 * @param position specified position for object
	 */
	public SymbolButton(String val, int x, int y){
		value = val;
		new JButton();
		setText(value);
		addListener();
		setSize(x,y);
	}
	
	/**
	 * Creates a button with it's corresponding symbol value and label
	 * @param l label of button
	 * @param value corresponding value
	 */
	public SymbolButton(String l,String val){
		value = val;
		new JButton();
		setText(l);
		addListener();
	}
	
	/**
	 * Creates a button with it's corresponding symbol value and label, and specified position
	 * @param l label of button
	 * @param value corresponding value
	 * @param position position of the button
	 */
	public SymbolButton(String l,String val, int x, int y){
		value = val;
		new JButton();
		setText(l);
		addListener();
		setSize(x,y);
	}
	
	/**
	 * Adds the action listener to the object
	 * 
	 * @author Balazs Pete
	 */
	private void addListener(){
		addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				
				main.MainWindow.insertText(value);
				main.MainWindow.textAreaFocus();
			}
			
		});
	}
}
